<!--

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at
	
		http://www.apache.org/licenses/LICENSE-2.0
   
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.

-->

<ui:component
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:cs="http://java.sun.com/jsf/composite"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	
	<cs:interface componentType="summer.faces.CompositeComponent" componentClass="${empty cc.attrs.type ? 'text' : cc.attrs.type}">
		<cs:attribute name="dataLabel" required="false" />
		<cs:attribute name="size" required="false" />
		<cs:attribute name="title" required="false" />
		<cs:attribute name="type" required="false" />
		<cs:attribute name="value" required="false" />
	</cs:interface>
	
	<cs:implementation>
		
		<ui:fragment rendered="${not empty cc.attrs.type and cc.attrs.type.matches('hidden|submit|reset')}">
			${cc.renderer.beginElement(cc, 'input')}
			${cc.renderer.endElement(cc, 'input')}
		</ui:fragment>
		
		<ui:fragment rendered="${not empty cc.attrs.type and cc.attrs.type.matches('checkbox|radio')}">
			${cc.renderer.beginElement(cc, 'input')}
			${cc.renderer.endElement(cc, 'input')}
			<ui:fragment rendered="${not empty cc.attrs.dataLabel}">
				<label for="${cc.formId}" title="${cc.attrs.title}">${cc.attrs.dataLabel}</label>
			</ui:fragment>
			<h:outputText rendered="${(empty cc.attrs.dataError or cc.attrs.dataError) and not empty cc.formName and not empty errors.get(cc.formName)}"
				value="${errors.get(cc.formName).message}" styleClass="error" escape="false" />
		</ui:fragment>
		
		<ui:fragment rendered="${empty cc.attrs.type or not cc.attrs.type.matches('hidden|submit|reset|checkbox|radio')}">
			<ui:fragment rendered="${not empty cc.attrs.dataLabel}">
				<label for="${cc.formId}" title="${cc.attrs.title}">${cc.attrs.dataLabel}</label>
			</ui:fragment>
			${cc.renderer.beginElement(cc, 'input')}
			${cc.renderer.endElement(cc, 'input')}
			<h:outputText rendered="${(empty cc.attrs.dataError or cc.attrs.dataError) and not empty cc.formName and not empty errors.get(cc.formName)}"
				value="${errors.get(cc.formName).message}" styleClass="error" escape="false" />
		</ui:fragment>
		
	</cs:implementation>
	
</ui:component>